import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ItemData } from "../../../resource/info/ItemData";
import { TSkill } from "../../../../../Message/Db/Tables/TSkill";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { TSkillItem } from "./TSkillItem";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Language } from "../../../../../extend/language/Language";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { PetSkillUtil } from "./PetSkillUtil";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class BatchRefreshRenderer
    
    export  class BatchRefreshRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            this.registToolTip();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._itemData = arg1["itemData"] as ItemData;
            this._skill = arg1["skill"] as TSkill;
            LoaderHelp.addResCallBack(ResFileConst.petSkillRand, this.onUpdateBitmapHandler);
            this.updateByTSKill(this._skill);
            return;
        }

        /* internal  */onUpdateBitmapHandler(): void
        {
            if (this._skill) 
            {
                this._qBitmap.bitmapData = null;
            }
            else 
            {
                this._qBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.QuestionMark);
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 120, 140, this);
            ObjCreate.createBg(30, 15, 68, 68, this, ImagesConst.PackItemBg);
            this._qBitmap = GlobalClass.getBitmap(ImagesConst.QuestionMark);
            this._qBitmap.width = 45;
            this._qBitmap.height = 64;
            this._qBitmap.x = 40;
            this._qBitmap.y = 15;
            this.addChild(this._qBitmap);
            this._tskillItem = new TSkillItem();
            this._tskillItem.setSize(60, 60);
            this._tskillItem.move(34, 19);
            this.addChild(this._tskillItem);
            this._nameTxt = ObjCreate.createTextField("", 0, 85, 120, 50, this, new GTextFormat(FontUtil.songtiName, 16, 16711935, true));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._getBtn = ObjCreate.createGButton(Language.getString(54117), 25, 110, 70, 24, this);
            this._getBtn.drawNow();
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            return;
        }

        /* internal  */registToolTip(): void
        {
            this._getBtn.toolTipData = HTMLUtil.addColor("<textFormat leading=\'5\'>" + Language.getString(54118) + "</textFormat>", "#ffffff");
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (!arg1) 
            {
            };
            return;
        }

        /* internal  */updateByTSKill(arg1: TSkill): void
        {
            this._tskillItem.skill = arg1;
            if (arg1) 
            {
                this._colorSkillName = HTMLUtil.addColor(arg1.skillName, PetSkillUtil.getColorByLevel(arg1.skillLevel));
                this._nameTxt.htmlText = this._colorSkillName;
            }
            else 
            {
                this._nameTxt.text = "";
            }
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onGetOkClickHandler: Function;

            var loc1;
            e = arg1;
            if (this._itemData && this._skill) 
            {
                onGetOkClickHandler = (arg1: int): void
                {
                    if (arg1 == Alert.OK) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetMakeSkillProp, {"uid": _itemData.uid, "skillId": _skill.skillId}));
                    }
                    return;
                }
                Alert.show(Language.getStringByParam(54612, this._colorSkillName), null, Alert.OK | Alert.CANCEL, null, onGetOkClickHandler);
            }
            return;
        }

        /* internal */ /* var */_qBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_tskillItem: TSkillItem;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_skill: TSkill;

        /* internal */ /* var */_colorSkillName: string;
    }
